import echarts from 'echarts';
let install = function(Vue) {
	Object.defineProperties(Vue.prototype, {
		$chart: {
			get() {
				return {
					//一个简单的示例
					first_bar: function(id) {
						this.chart = echarts.init(document.getElementById(id));
						this.chart.clear();
						const optionData = {
							title: {
								text: 'ECharts 入门示例'
							},
							tooltip: {},
							xAxis: {
								data: [ '衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子' ]
							},
							yAxis: {},
							series: [
								{
									name: '销量',
									type: 'bar',
									data: [ 5, 20, 36, 10, 10, 20 ]
								}
							]
						};
						this.chart.setOption(optionData);
					},
					// 柱状图
					Ladder: function(id, keys, count) {
						this.chart = echarts.init(document.getElementById(id));
						this.chart.clear();
						const optionData = {
							title: {
								text: 'IP分布表'
							},
							tooltip: {
								trigger: 'axis',
								axisPointer: {
									type: 'shadow'
								}
							},
							legend: {},
							grid: {
								left: '3%',
								right: '4%',
								bottom: '3%',
								containLabel: true
							},
							xAxis: {
								type: 'value',
								boundaryGap: [ 0, 0.01 ]
							},
							yAxis: {
								type: 'category',
								data: keys
							},
							series: [
								{
									name: '2021',
									type: 'bar',
									data: count
								}
							]
						};
						this.chart.setOption(optionData);
					},
					// 饼图
					Pie: function (id, arr) {
						this.chart = echarts.init(document.getElementById(id));
						this.chart.clear();
						const optionData = {
							title: {
								text: '运营商分布饼图',
								subtext: '',
								left: 'center'
							},
							tooltip: {
								trigger: 'item'
							},
							legend: {
								orient: 'vertical',
								left: 'left'
							},
							series: [
								{
									name: 'Access From',
									type: 'pie',
									radius: '50%',
									data: arr,
									emphasis: {
										itemStyle: {
											shadowBlur: 10,
											shadowOffsetX: 0,
											shadowColor: 'rgba(0, 0, 0, 0.5)'
										}
									}
								}
							]
						};
						this.chart.setOption(optionData);
					}
				};
			}
		}
	});
};
export default {
	install
};
